package com.mydb;

import org.dom4j.Document;

import com.mydb.util.PropertiesUtil;
import com.mydb.xml.XMLBuilder;

public class Connection {
	
	public static Connection conn;
	
	private Connection() {

	}
	
	public static Connection getInstance() {
		if(conn == null) {
			conn = new Connection(); 
		}
		return conn;
	}
	
	public MyDbObject getConnection(String databaseName) {
		XMLBuilder builder = XMLBuilder.getInstance();
		Document doc = builder.getRootElement(databaseName);
		MyDbObject object = new MyDbObject();
		object.setDbName(databaseName);
		object.setDbDoc(doc);
		return object;
	}
	
	public MyDbObject newDatabase(String databaseName) {
		XMLBuilder builder = XMLBuilder.getInstance();
		Document doc = builder.createRootElement(databaseName);
		MyDbObject object = new MyDbObject();
		object.setDbName(databaseName);
		object.setDbDoc(doc);
		return object;
	}
	
}
